(function($){
	$.fn.jquerymove = function(){
		var moveobj = $(this);
		var old_position = {};
		var new_position = {};
		var offset = {};
		var p_offset = {};
		var isover = 1;
		var getTopIndex = function () {
			var divs = $('div');
			var topIndex = 0;

			divs.each(function (key,val){
				var _tmp = parseInt($(val).css('z-index'))
				if (!isNaN(_tmp) && _tmp > topIndex) {
					topIndex = _tmp;
				}
			});
			return topIndex;
		}
		moveobj.css({cursor: "move" });
		moveobj.mousedown(
			function (e) {
				var zindex = getTopIndex()+1;
				moveobj.css({position: "absolute",cursor: "move",zIndex : zindex });
				old_position = {X:e.clientX,Y:e.clientY};
				offset = moveobj.offset();
				p_offset = moveobj.parent().offset();
				isover = 0;
			}
		);

		moveobj.mouseup(
			function (e) {
				isover = 1;
			}
		);
		$(document).mousemove(
			function (e) {
				if (!isover) {
					new_position = {X:e.clientX,Y:e.clientY};
					var _left = offset.left+new_position.X-old_position.X-p_offset.left;
					var _top = offset.top+new_position.Y-old_position.Y-p_offset.top;
//					if (typeof console != 'undefined' && typeof console.log == 'function') {
//			            console.log("top:"+_top + " : left:" + _left + " : isover : " + isover);
//			        }
//					if (_left >760) {
//						_left = 760;
//					}
//					if (_left <0) {
//						_left = 0;
//					}
//					if (_top >500) {
//						_top = 500;
//					}
//					if (_top <0) {
//						_top = 0;
//					}
					moveobj.css({
						left: _left,
						top: _top
					})
				}
			}
		);
	}
})(jQuery);